<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.1/jquery.min.js"></script>
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css" integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous">
    <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
    <script th:src="@{/static/main.js}"></script>

</head>
<body>
<!--产品详情页-->


<div class="container-fluid" id="app" style="margin-top: 5px;margin-bottom: 100px">


    <div class="container" style="margin-top: 20px">
        <div class="row">
            <div class="col-sm-6 col-md-12">
                <div class="thumbnail" style="box-shadow: 5px 5px 3px 0px #CCCCCC;padding-bottom: 20px">
                    <img :src="product.productImg" alt="..." class="col-sm-2 col-md-2">
                    <div class="caption text-left">
                        <h3> <span v-text="product.productName">productName</span></h3>
                        <p class="text-danger" style="font-size: larger;font-weight: bold;font-family: 'Lora',serif"><span v-text="'￥'+product.productPrice + '元'">typeName</span></p>
                        <p class="text-muted" style="font-size: larger;font-weight: bold;font-family: 'Lora',serif">销售量:<span v-text="product.buyCount">buyCount</span></p>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <div class="container" v-if="commentVos.length<=0">
        <h3 style="text-align: center" class="text-danger">该商品还没有相关评论哦~</h3>
    </div>

    <div class="container" v-if="commentVos.length>0">

        <div class="row">
            <div class="col-md-12">
                <p style="background-color: #458b74 ; color: white; font-size: 30px; padding-left: 10px; border-radius: 4px">商品评价<span class="pull-right" v-text="total+'条评论'"></span>
            </div>
        </div>

        <div class="row">
            <div class="col-sm-6 col-md-12" v-for="commentVo in commentVos">
                <div class="thumbnail row gy-5" style="box-shadow: 5px 5px 3px 0px #CCCCCC">
                    <img style="width:70px; height:60px;margin-top: 8px"  v-if="commentVo.userImg" :src="commentVo.userImg" alt="..." class="col-sm-2 col-md-2 img-circle">
                    <img style="width:70px; height:60px;margin-top: 8px" v-if="!commentVo.userImg" src="/static/109951166155909486.jpg" alt="..." class="col-sm-2 col-md-2 img-circle">
                    <div class="caption text-left">
                        <p><span style="font-size:18px;font-weight: bold" v-text="commentVo.username"></span><span class="pull-right" v-text="commentVo.createTime">typeName</span></p>
                        <p class="row mt-3"><span style="font-size:12px" v-text="commentVo.productName"></span></p>
                    </div>
                    <p class="text-muted" style="font-size: larger;font-weight: bold;font-family: 'Lora',serif">&nbsp&nbsp&nbsp&nbsp<span v-text="commentVo.content"></span></p>
                </div>
            </div>
        </div>


        <div class="row">
            <div class="col-md-offset-5 col-lg-offset-4col-xl-offset-5">
                <ul class="pagination justify-content-center">
                    <li><a href="javascript:void(0)" @click.prevent="go(currentPage-1)">&laquo;</a></li>
                    <li><a href="javascript:void(0)" v-for="n in totalPages" v-text="n" @click.prevent="go(n)">n</a>
                    </li>
                    <li><a href="javascript:void(0)" @click.prevent="go(currentPage+1)">&raquo;</a></li>
                </ul>
            </div>
        </div>

    </div>





</div>
<script>

    console.log(".........index...........")

    let index = new Vue({
        el: "#app"
        ,
        data: {
            productId: [[${productId}]],
            product:{},
            commentVos:[],
            currentPage: 1,
            pageSize: 2,
            total: 0,
            totalPages: 0,
        }
        ,
        methods: {
            initProduct(){
                let _this=this;
                $.get("/product/queryProductDetail",{productId: _this.productId},function (data){
                      _this.product=data;
                })
            },
            initComments(){
                let _this=this;
                let params = {
                    currentPage: _this.currentPage,
                    pageSize: _this.pageSize,
                    productId: _this.productId,
                }
                $.get("/comment/select",params,function (data){
                    _this.commentVos = data.records;
                    _this.currentPage = data.current;
                    _this.pageSize = data.size;
                    //数据总量
                    _this.total = data.total;
                    //总页数
                    _this.totalPages = data.pages;
                })

            },
            go(pageNum) {
                //小于1 或者 大于total 或者 仍获取当前页数据 直接返回
                if (pageNum < 1 || pageNum > this.totalPages || pageNum == this.currentPage) {
                    console.log(pageNum + " 无效页码值")
                    return;
                }

                this.currentPage = pageNum;
                this.initComments();
            }

        }
        ,
        created(){
            this.initProduct()
            this.initComments();
        }

    });


</script>
</body>
</html>


